//package com.turing.post.capitalaccounts.impl;
//
//import java.math.BigInteger;
//import java.util.Date;
//import java.util.List;
//
//import javax.ejb.Local;
//import javax.ejb.Remote;
//import javax.ejb.Stateless;
//import javax.persistence.EntityManager;
//import javax.persistence.PersistenceContext;
//import javax.persistence.Query;
//
//import com.turing.post.capitalaccounts.util.SaleCreditAdjustBill;
//import com.turing.post.capitalaccounts.util.SaleCreditAdjustBillDao;
//import com.turing.post.util.Config;
//import com.turing.post.util.GeneralDao;
//import com.turing.post.util.PCPSApplicationException;
//import com.turing.post.util.PCPSUtil;
//import com.turing.post.util.PCPSWebInput;
//
//@Stateless(mappedName = "capitalaccounts.impl.SaleCreditAdjustBillDaoImpl")
//@Remote
//@Local
//public class SaleCreditAdjustBillDaoImpl implements SaleCreditAdjustBillDao {
//
//	/**
//	 * 实体管理器
//	 */
//	@PersistenceContext
//	protected EntityManager _em;
//	
//	@Override
//	public SaleCreditAdjustBill getSaleCreditAdjustBillById(BigInteger id) {
//		return _em.find(SaleCreditAdjustBill.class, id);
//	}
//
//	@Override
//	public SaleCreditAdjustBill getSaleCreditAdjustBillByIdForUpdate(
//			BigInteger id) {
//		Query query = _em.createNativeQuery(
//				"select t.* from SaleCreditAdjustBill t where t.salecreditadjustbillid= ?1 for update",SaleCreditAdjustBill.class);
//		query.setParameter(1, id);
//		return (SaleCreditAdjustBill) query.getSingleResult();
//	}
//	
//	@Override
//	public void insertSaleCreditAdjustBill(SaleCreditAdjustBill obj)
//			throws PCPSApplicationException {
//		GeneralDao.insert(_em, obj);
//	}
//
//	@SuppressWarnings("unchecked")
//	@Override
//	public List<SaleCreditAdjustBill> getSaleCreditAdjustBillList(PCPSWebInput webInput,
//			Date startTranDate, Date endTranDate, BigInteger startAmount,
//			BigInteger endAmount, String saleBranchNo,Integer page) {
//		if (PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
//			 return null;
//		}
//		String issueCompanyNo = PCPSUtil.getIssueCompanyNo(webInput);
//		if (page == null || page < 0){
//			page=0;
//		}
//		String sqlwhere="";
//		if (!PCPSUtil.isEmpty(saleBranchNo)){
//			sqlwhere += " and t.salebranchno like rtrim('" + saleBranchNo
//					+ "','0')||'%'";
//		}else{
//			return null;
//		}
//		if(null!=startAmount){
//			sqlwhere+=" and t.amount>="+startAmount;
//		}
//		if(null!=endAmount){
//			sqlwhere+=" and t.amount<="+endAmount;
//		}
//		if(null!=startTranDate){
//			sqlwhere+=" and t.trantime>=to_date('"+PCPSUtil.getPackedYMDString2(startTranDate)+" 00:00:00','yyyy-MM-dd hh24:mi:ss')";
//		}
//		if(null!=endTranDate){
//			sqlwhere+=" and t.trantime<=to_date('"+PCPSUtil.getPackedYMDString2(endTranDate)+" 23:59:59','yyyy-MM-dd hh24:mi:ss')";
//		}
//		sqlwhere+=" order by t.trantime desc";
//		String sql="select t.* from salecreditadjustbill t where IssueCompanyNo='"+issueCompanyNo+"' "+sqlwhere;
//		int maxResult = Config.PAGE_SIZE;
//		int startPosition = maxResult * page;
//		Query query = _em.createNativeQuery(sql,SaleCreditAdjustBill.class);
//		query.setFirstResult(startPosition);
//		query.setMaxResults(maxResult);
//		return query.getResultList();
//	}
//
//	@Override
//	public Integer getSaleCreditAdjustBillTotal(PCPSWebInput webInput,
//			Date startTranDate, Date endTranDate, BigInteger startAmount,
//			BigInteger endAmount, String saleBranchNo) {
//		if (PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
//			 return 0;
//		}
//		String issueCompanyNo = PCPSUtil.getIssueCompanyNo(webInput);
//		
//		String sqlwhere="";
//		if (!PCPSUtil.isEmpty(saleBranchNo)){
//			sqlwhere += " and t.salebranchno like rtrim('" + saleBranchNo
//					+ "','0')||'%'";
//		}else{
//			return null;
//		}
//		if(null!=startAmount){
//			sqlwhere+=" and t.amount>="+startAmount;
//		}
//		if(null!=endAmount){
//			sqlwhere+=" and t.amount<="+endAmount;
//		}
//		if(null!=startTranDate){
//			sqlwhere+=" and t.trantime>=to_date('"+PCPSUtil.getPackedYMDString2(startTranDate)+" 00:00:00','yyyy-MM-dd hh24:mi:ss')";
//		}
//		if(null!=endTranDate){
//			sqlwhere+=" and t.trantime<=to_date('"+PCPSUtil.getPackedYMDString2(endTranDate)+" 23:59:59','yyyy-MM-dd hh24:mi:ss')";
//		}
//		String sql="select nvl(count(*),0) from salecreditadjustbill t where IssueCompanyNo='"+issueCompanyNo+"' "+sqlwhere;
//		Query query = _em.createNativeQuery(sql);
//		return Integer.parseInt(query.getSingleResult().toString());
//	}
//}
